package com.example.tableapplication;

import android.app.ActionBar;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;

import java.util.ArrayList;
import java.util.List;

public class TableUtil {
    public static List<TableRow> addSingleRecord(int width, Context context, String row, String billno, String[] columnKey, String[] columnHead) {
        List<TableRow> table = new ArrayList<TableRow>();
        View c=new CheckBox(context);
        try{
//            TableCell[] body1 = new TableCell[1];
//            body1[0] = new TableCell("第"+j+"行", 2*width, ActionBar.LayoutParams.MATCH_PARENT, TableCell.STRING);
//            table.add(new TableRow(body1));
            TableCell[] titles = new TableCell[2];// 每行2个单元
            titles[0] = new TableCell(row, width, ActionBar.LayoutParams.MATCH_PARENT, TableCell.STRING);
            titles[1] = new TableCell(billno, width, ActionBar.LayoutParams.MATCH_PARENT, TableCell.CHECKBOX);
//            titles[1] = new TableCell("字段值", width, ActionBar.LayoutParams.MATCH_PARENT, TableCell.STRING);
            table.add(new TableRow(titles));
            int size = columnHead.length;
//            JSONObject jsonObj = new JSONObject(jsonObjStr);
                for (int i = 0; i < size; i++) {
                    TableCell[] body = new TableCell[2];// 每行2个单元
                    String col = columnKey[i];
                    body[0] = new TableCell(columnHead[i], width, ActionBar.LayoutParams.MATCH_PARENT, TableCell.STRING);
                    body[1] = new TableCell(col, width, ActionBar.LayoutParams.MATCH_PARENT, TableCell.STRING);
                    table.add(new TableRow(body));
                }

        }catch(Exception e) {
            Log.d("添加表格异常", "Error:", e);
        }
        return table;
    }

}
